#ifndef _SCARD_H
#define _SCARD_H

#define _SDCARD

#ifdef _SDCARD

#include <stdint.h>

#define sCARD_DUMMY_BYTE            (0xFF)
#define sCARD_SINGLE_BLOCK_READ     (0xFE)
#define sCARD_SINGLE_BLOCK_WRITE    (0xFE)
#define sCARD_MULTI_BLOCK_READ      (0xFD)
#define sCARD_MULTI_BLOCK_WRITE     (0xFD)
#define sCARD_BLOCK_SIZE            (512)

enum sCardTypeStatus{
    sCARD_TYPE_ERROR = 0x00,
    sCARD_TYPE_MMC = 0x01,
    sCARD_TYPE_V1 = 0x02,
    sCARD_TYPE_V2 = 0x04,
    sCARD_TYPE_V2HC = 0x06,
};
typedef enum sCardTypeStatus  sCardTypeStatus_t;

enum sCardCommand{
    sCARD_COMMAND_0 = 0, /*card device reset*/
    sCARD_COMMAND_1 = 1, /*send op command*/
    sCARD_COMMAND_8 = 8, /*send if conf*/
    sCARD_COMMAND_9 = 9, /*read card csd date*/
    sCARD_COMMAND_10 = 10, /*read card cid date*/
    sCARD_COMMAND_12 = 12, /*date transmit stop*/
    sCARD_COMMAND_16 = 16, /* set sector size*/
    sCARD_COMMAND_17 = 17, /* read sector*/
    sCARD_COMMAND_18 = 18, /* read multi sector*/
    sCARD_COMMAND_23 = 23, /* set multi sector,need erase N blocks before write date*/
    sCARD_COMMAND_24 = 24, /*write sector*/
    sCARD_COMMAND_25 = 25, /* write multi sector*/
    sCARD_COMMAND_41 = 41, /* response command return 0x00*/
    sCARD_COMMAND_55 = 55, /* response command return 0x01*/
    sCARD_COMMAND_58 = 58, /* read card OCR*/
    sCARD_COMMAND_59 = 59, /* command: enable or disable OCR*/
};
typedef enum sCardCommand sCardCommand_t;

enum sCardDateStatus{
    sCARD_DATE_RES_OK = 0x05,
    sCARD_DATE_CRC_ERROR = 0x0B,
    sCARD_DATE_WRITE_ERROR = 0x0D,
    sCARD_DATE_OTHER_ERROR = 0xFF,
};
typedef enum sCardDateStatus sCardDateStatus_t;

enum sCardMSDStatus{
    sCARD_MSD_RES_OK = 0x00,
    sCARD_MSD_IN_IDLE = 0x01,
    sCARD_MSD_ERASE_RESET = 0x02,
    sCARD_MSD_ILLEGAL_COMMAND = 0x04,
    sCARD_MSD_COMMAND_CRC_ERROR = 0x08,
    sCARD_MSD_ERASE_SEQUENCE_ERROR = 0x10,
    sCARD_MSD_ADDRESS_ERROR = 0x20,
    sCARD_MSD_PARAMETER_ERROR = 0x40,
    sCARD_MSD_OTHER_ERROR = 0x80,
    sCARD_MSD_RES_FAIL = 0xFF,
};
typedef enum sCardMSDStatus  sCardMSDStatus_t;

struct sCardOps{
    void (*sCardInit)(void);
    uint8_t (*sCardReadWrite)(uint8_t);
    void (*sCardSetSpeed)(uint8_t);
    void (*sCardStatusSet)(uint8_t);
    sCardTypeStatus_t sCardType;
};
typedef struct sCardOps sCardOps_t;

#ifdef __cplusplus
extern "C"{
#endif
extern int8_t sCardInit(void);
extern int8_t sCardWrite(void *date,uint32_t sector,uint8_t size);
extern int8_t sCardRead(void *date,uint32_t sector,uint8_t size);
extern int32_t sCardGetSectorSize(void);

#ifdef __cplusplus
}
#endif


#endif

#endif
